package gui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class Reception extends JFrame {
	private static final long serialVersionUID = 1L;

	public Reception() {
		setTitle("Main Window");
		init();
	}

	private void init() {
		setBounds(380, 150, 240, 275);
		setResizable(false);

		setIconImage(Toolkit.getDefaultToolkit().getImage("ico.PNG"));

		Font f = new Font(Font.DIALOG_INPUT, Font.ITALIC, 12);

		JPanel p = new JPanel();
		p.setLayout(null);
		p.setBackground(Color.black);

		final JLabel Se = new JLabel("Secant");
		Se.setBounds(20, 215, 200, 30);
		Se.setFocusable(false);
		// Se.setHorizontalAlignment((int) JLabel.CENTER_ALIGNMENT);
		Se.setFont(f);
		p.add(Se);

		final JLabel BS = new JLabel("BiSection");
		BS.setBounds(20, 180, 200, 30);
		BS.setFocusable(false);
		// BS.setHorizontalAlignment((int) JLabel.CENTER_ALIGNMENT);
		BS.setFont(f);
		p.add(BS);

		final JLabel FP = new JLabel("Fixed point");
		FP.setBounds(20, 145, 200, 30);
		FP.setFocusable(false);
		// FP.setHorizontalAlignment((int) JLabel.CENTER_ALIGNMENT);
		FP.setFont(f);
		p.add(FP);

		final JLabel FB = new JLabel("False Position");
		FB.setBounds(20, 110, 200, 30);
		FB.setBackground(Color.black);
		// FB.setHorizontalAlignment((int) JLabel.CENTER_ALIGNMENT);
		FB.setFont(f);
		p.add(FB);

		final JLabel NR = new JLabel("Newton Raphson");
		NR.setBounds(20, 75, 200, 30);
		NR.setFocusable(false);
		// NR.setHorizontalAlignment((int) JLabel.CENTER_ALIGNMENT);
		NR.setFont(f);
		p.add(NR);

		final JLabel LA = new JLabel("Lagrange Approximation");
		LA.setBounds(20, 40, 200, 30);
		LA.setFocusable(false);
		// LA.setHorizontalAlignment((int) JLabel.CENTER_ALIGNMENT);
		LA.setFont(f);
		p.add(LA);

		final JLabel NDD = new JLabel("Newton Divided Difference");
		NDD.setBounds(20, 5, 200, 30);
		NDD.setFocusable(false);
		// NDD.setHorizontalAlignment((int) JLabel.CENTER_ALIGNMENT);
		NDD.setFont(f);
		p.add(NDD);

		MouseListener lis = new MouseListener() {
			@Override
			public void mouseReleased(MouseEvent e) {
				JLabel l = (JLabel) e.getSource();
				if (l == BS)
					new BiFalse(true).setVisible(true);
				else if (l == FB)
					new BiFalse(false).setVisible(true);
				else if (l == FP)
					new FixedNewton(true).setVisible(true);
				else if (l == NR)
					new FixedNewton(false).setVisible(true);
				else if (l == Se)
					new Secant().setVisible(true);
				else if (l == NDD)
					new LarND(false).setVisible(true);
				else if (l == LA)
					new LarND(true).setVisible(true);
			}

			@Override
			public void mousePressed(MouseEvent e) {
				((JLabel) e.getSource()).setForeground(Color.red);
			}

			@Override
			public void mouseExited(MouseEvent e) {
				((JLabel) e.getSource()).setForeground(null);
			}

			@Override
			public void mouseEntered(MouseEvent e) {
				((JLabel) e.getSource()).setForeground(Color.white);
				Toolkit.getDefaultToolkit().beep();
			}

			@Override
			public void mouseClicked(MouseEvent e) {
				((JLabel) e.getSource()).setForeground(Color.cyan);
			}
		};

		FB.addMouseListener(lis);
		BS.addMouseListener(lis);
		FP.addMouseListener(lis);
		Se.addMouseListener(lis);
		NR.addMouseListener(lis);
		NDD.addMouseListener(lis);
		LA.addMouseListener(lis);

		add(p);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

}
